

//#include"Task.hpp"
#include<string>
#include<vector>
#include<unistd.h>
#include<ctime>
#include"BlockQueue.hpp"
#include"Thread.hpp"
using namespace ThreadModule;
int a = 10;


void Consumer(Blockqueue<int> &bq)
{
    while (true)
    {
       int data;
       bq.pop(&data);
       std::cout<<"consymer consum data is:"<<data<<"arr:"<< &bq <<std::endl;
     sleep(2);
    }
    
}
void Productor(Blockqueue<int> &bp)
{
    int cnt =1;
    while (true)
    {
        bp.Enqueue(cnt);
        std::cout<<"Productor product data is:"<<cnt<<"addr:"<<&bp<<std::endl;
        cnt++;
    }
    
}
void StartComm(std::vector<Thread<Blockqueue<int>>> *threads,int num,Blockqueue<int> &bq,func_t<Blockqueue<int>> func)
{
    for(int i = 0;i<num;++i)
    {
        std::string name = "thread-"+std::to_string(i+1);
        threads->emplace_back(func,bq,name); 
        threads->back().Start();
    }
}
void StartConsumer(std::vector<Thread<Blockqueue<int>>> *threads,int num,Blockqueue<int> &bq)
{
    StartComm(threads,num,bq,Consumer);
}
void StartProductor(std::vector<Thread<Blockqueue<int>>> *threads,int num,Blockqueue<int> &bq)
{
    StartComm(threads,num,bq,Productor);
}
void WaitALLThread(std::vector<Thread<Blockqueue<int>>> &threads)
{
    for(auto &thread :threads)
    {
        thread.Join();
    }
}
int main()
{
    Blockqueue<int> *bq = new Blockqueue<int>(5);
    std::vector<Thread<Blockqueue<int>>> threads;
    StartConsumer(&threads,1,*bq);
   StartProductor(&threads,1,*bq);
    WaitALLThread(threads);
    return 0;
}